<template>
  <div class="dispatch">
    <div class="head">
      <div class="icon"><img src="https://klcx-bucket.oss-cn-beijing.aliyuncs.com/klcx-xcx/ico/icon_dis.png"></div>
      <wxParse :content="orderInfo.dispatchTitle" className="wxParse-tips"></wxParse>
      <div class="button"><button class="btn" @click="back()" :disabled="disable">{{orderInfo.dispatchButton}}</button></div>
    </div>
    <div class="img"><img :src="orderInfo.imageUrl"></div>
    <div class="unlock">
      <unlock @unlockSuccess="unlockSuccess"></unlock>
    </div>
  </div>

</template>

<script>
  import wxParse from 'mpvue-wxparse'
  import unlock from '@/components/unlock'
  import Service from '@/utils/service'

  export default {
    components: {
      wxParse, unlock
    },
    data () {
      return {
        orderInfo: {},
        latitude: 0,
        longitude: 0,
        disable:false
      }
    },
    onLoad(options) {
      this.orderInfo = JSON.parse(options.orderInfo)
      let str = this.orderInfo.dispatchTitle
      this.orderInfo.dispatchTitle = str.replace(/\n/g,"<br/>")
    },
    onShow(){},
    methods: {
      unlockSuccess() {
        this.preReturnBike()
      },
      preReturnBike() {
        let _this = this
        let localtion = wx.getStorageSync('localtion');
        let data = {
          orderNo: this.orderInfo.orderNo,
          mobileLatitude: localtion.latitude,
          mobileLongitude: localtion.longitude
        }
        Service.preReturnBike(data).then((res) => {
          clearInterval(this.time)
          switch (res.code) {
            case 200:
              let data = res.data
              data.orderNo = this.orderInfo.orderNo
              let orderInfo = JSON.stringify(data);
              wx.redirectTo({
                url: '../returnCar/main?orderInfo='+orderInfo
              })
              break
            case 400: //订单已经还车未结算跳转支付页面
              wx.reLaunch({
                url: '../waitPay/main?autoPay=1&orderNo='+this.orderInfo.orderNo
              })
              break
            case 401: //订单已经取消跳转首页
              setTimeout(() => {
                wx.reLaunch({
                  url: '../index/main'
                })
              },200)
              break
            case 403: //订单未使用取消订单
              setTimeout(() => {
                wx.reLaunch({
                  url: '../index/main'
                })
              },200)
              break
//            case 411: //还车区外不可还车
//              wx.redirectTo({
//                url: '../prohibit/main?type=1'
//              })
//              break
            case 412: //禁还区域
              wx.navigateTo({
                url: '../prohibit/main?type=1'
              })
              break
          }
        })
      },
      back() {
        this.disable=true
        wx.navigateBack({
          delta: 1
        })
        setTimeout(()=>{
          this.disable=false
        },200)
      }
    }
  }
</script>

<style scoped lang="stylus">
  .dispatch
    .head
      height 520px
      background: #FF5E5E
      text-align center
      .icon
        padding 69px 0 28px
        img
          width 94px
          height: 94px
      .button
        .btn
          display: inline-block
          width 408px
          margin-top 30px
          margin-bottom 50px
          background #FFFFFF
          font-size 30px
          color: #FF5E5E
    .img
      img
        width 100%
        height 415px
    .unlock
      width 600px
      margin 0 auto
      padding-top 30px
</style>
